/*
* Unit Test Bootstrap
* Autor: Tomasz Jaworski, 2018-2019
*
* Test dla zadania Histogram
* Autor testowanej odpowiedzi: Szymon Ptak
* Test wygenerowano automatycznie o 2019-08-22 14:46:23.093005
*
* Debug:
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <signal.h>
#include <setjmp.h>
#include <assert.h>
#define _RLDEBUG_API_
#include "unit_helper_v2.h"
#include "rdebug.h"
#include "tested_declarations.h"
#include "rdebug.h"
//
// Elementy globalne dla całego testu
//
//
// Test 1: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST1(void)
{
// informacje o teście
test_start(1, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
const int expected_array[] = {0, 0, 0, 0, 0, 3, 0, 0, 1, 0, 0};
int output[] = {2, 1, -2, 0, 2, -2, -1, 2, -1, -2, -1};
printf("#####START#####");
int res = create_histogram((float[]){5.711182, 8.353616, 5.839582, 5.170182}, 4, output, 11);
printf("#####END#####");
test_error(res == 0, "Funkcja create_histogram() powinna zwrócić 0, a zwróciłą %d", res);
int ok = 0;
for (int i = 0; i < 11; ++i)
ok += output[i] != expected_array[i];
if (ok)
{
printf("Powinno być: [0, 0, 0, 0, 0, 3, 0, 0, 1, 0, 0]\n");
printf("\nTablica po wywołaniu funkcji create_histogram: ");
for (int i = 0; i < 11; ++i)
printf("%d ", output[i]);
printf("\n");
test_error(ok == 0, "Funkcja create_histogram() niepoprawnie wypełniła tablicę");
}
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 2: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST2(void)
{
// informacje o teście
test_start(2, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
const int expected_array[] = {6, 11, 9, 8, 7, 6, 13, 6, 13, 15, 6};
int output[] = {0, 0, 1, -1, -2, 0, -1, 0, 1, 1, -2};
printf("#####START#####");
int res = create_histogram((float[]){9.941554, 6.378754, 9.244984, 5.952509, 6.067851, 4.649873, 1.142815, 5.253298, 4.862896, 9.949724, 0.387957, 0.181615, 6.756926, 9.948668, 8.896092, 6.966488, 3.351933, 3.273143, 9.427932, 10.204406, 9.199451, 7.475066, 0.733212, 10.441716, 6.120441, 9.028251, 9.491175, 2.246896, 0.858988, 2.741693, 10.257991, 1.134922, 8.415881, 1.940359, 7.665992, 9.998259, 3.398976, 6.972785, 3.075263, 2.372870, 5.146831, 8.296388, 2.304843, 1.281589, 10.084546, 6.942106, 3.868967, 8.737364, 8.270268, 8.089022, 6.719636, 4.428933, 8.077717, 0.661735, 8.871680, 1.164481, 6.378136, 4.510364, 1.672422, 9.334367, 5.403484, 9.637116, 10.489320, 1.385817, 8.769475, 3.455751, 2.659752, 7.604501, 7.210423, 6.203259, 1.315733, 8.036674, 4.204155, 8.185489, 2.070377, 5.141510, 3.011488, 7.727993, 9.466393, 4.623008, 2.619160, 6.245894, 6.928064, 7.869767, 5.087290, 9.027260, 1.960215, 2.071840, 6.563864, 2.737863, 1.267333, 3.188771, 9.198199, 10.701691, 8.145068, 8.457506, 1.225366, 9.956969, 0.882719, 4.506441}, 100, output, 11);
printf("#####END#####");
test_error(res == 0, "Funkcja create_histogram() powinna zwrócić 0, a zwróciłą %d", res);
int ok = 0;
for (int i = 0; i < 11; ++i)
ok += output[i] != expected_array[i];
if (ok)
{
printf("Powinno być: [6, 11, 9, 8, 7, 6, 13, 6, 13, 15, 6]\n");
printf("\nTablica po wywołaniu funkcji create_histogram: ");
for (int i = 0; i < 11; ++i)
printf("%d ", output[i]);
printf("\n");
test_error(ok == 0, "Funkcja create_histogram() niepoprawnie wypełniła tablicę");
}
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 3: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST3(void)
{
// informacje o teście
test_start(3, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
const int expected_array[] = {8, 12, 15, 15, 11, 12, 12, 11, 15, 11, 16};
int output[] = {-1, 0, 2, 1, -1, -2, 2, -1, 0, -2, -1};
printf("#####START#####");
int res = create_histogram((float[]){10.964682, 1.357403, 3.035852, 0.501355, 9.470451, 6.203325, 9.731243, 3.976463, 9.905779, 8.463556, 8.395962, 2.328298, 7.042873, 10.496411, 9.232320, 2.536839, 9.449114, 10.274167, 9.692380, 2.679822, 6.843290, 7.128989, 5.163220, 6.532663, 10.410999, 3.978996, 8.045740, 10.623278, 7.234360, 3.985613, 6.648996, 3.299676, 4.775635, 2.748508, 3.153708, 8.846973, 10.679946, 2.023838, 8.619395, 8.215617, 2.033891, 10.684331, 9.899725, 6.930890, 10.831633, 0.832885, 2.015910, 6.458598, 9.243452, 1.950921, 4.739876, 10.365825, 2.160546, 10.046241, 0.432107, 8.246589, 7.707924, 8.817988, 9.564055, 6.244891, 8.825969, 3.136544, 4.935653, 6.164909, 7.098311, 1.909649, 7.212165, 1.103212, 7.905313, 7.555700, 2.073037, 8.738536, 4.568896, 8.651281, 3.513051, 0.557837, 1.892762, 8.175569, 3.375586, 2.427925, 1.430629, 5.446315, 10.806118, 2.156779, 5.926297, 4.616001, 6.544168, 3.034395, 1.230125, 5.551661, 5.874148, 6.784124, 1.719836, 1.692511, 5.099677, 8.751181, 3.416549, 1.900461, 3.194528, 2.180184, 6.266337, 5.764261, 0.655143, 5.419645, 3.728400, 5.457227, 7.726376, 2.612338, 0.325963, 0.838455, 4.095187, 3.130702, 4.288043, 2.903875, 4.851789, 8.929996, 7.768201, 8.765709, 0.151984, 5.159559, 2.030118, 10.715772, 10.710782, 4.253498, 5.616452, 6.055196, 7.525171, 4.224431, 1.234648, 10.432837, 10.157576, 9.412027, 5.244680, 1.457007, 4.271862, 10.314033, 9.523573, 3.123708}, 138, output, 11);
printf("#####END#####");
test_error(res == 0, "Funkcja create_histogram() powinna zwrócić 0, a zwróciłą %d", res);
int ok = 0;
for (int i = 0; i < 11; ++i)
ok += output[i] != expected_array[i];
if (ok)
{
printf("Powinno być: [8, 12, 15, 15, 11, 12, 12, 11, 15, 11, 16]\n");
printf("\nTablica po wywołaniu funkcji create_histogram: ");
for (int i = 0; i < 11; ++i)
printf("%d ", output[i]);
printf("\n");
test_error(ok == 0, "Funkcja create_histogram() niepoprawnie wypełniła tablicę");
}
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 4: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST4(void)
{
// informacje o teście
test_start(4, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
const int expected_array[] = {1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0};
int output[] = {2, -2, -2, -1, 0, 2, -1, -2, -2, 0, 0};
printf("#####START#####");
int res = create_histogram((float[]){6.341412, -2.237893, 7.408610, -2.321861, 2.388285, 0.935989, -9.113723, -1.281404}, 8, output, 11);
printf("#####END#####");
test_error(res == 0, "Funkcja create_histogram() powinna zwrócić 0, a zwróciłą %d", res);
int ok = 0;
for (int i = 0; i < 11; ++i)
ok += output[i] != expected_array[i];
if (ok)
{
printf("Powinno być: [1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0]\n");
printf("\nTablica po wywołaniu funkcji create_histogram: ");
for (int i = 0; i < 11; ++i)
printf("%d ", output[i]);
printf("\n");
test_error(ok == 0, "Funkcja create_histogram() niepoprawnie wypełniła tablicę");
}
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 5: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST5(void)
{
// informacje o teście
test_start(5, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
const int expected_array[] = {4, 3, 6, 7, 4, 5, 1, 4, 8, 4, 0};
int output[] = {-2, 0, -2, -2, -1, -2, 2, 1, 1, -1, 1};
printf("#####START#####");
int res = create_histogram((float[]){3.281992, -0.645790, -2.556621, 8.438603, -7.573330, -3.032059, -3.036251, 2.201618, -2.567459, -7.370045, -1.219032, 3.252561, 8.665337, -6.090192, -6.288076, -7.011601, -2.224467, 9.251845, -4.718973, 0.483700, -7.741650, 8.791666, 3.178611, -1.865664, -0.636638, 3.018352, 1.677725, 7.699200, 2.468274, 2.992752, 7.379968, -2.636988, -5.734436, 0.017833, 5.647211, -4.999746, -6.340016, 4.411809, -4.853850, 2.823493, -2.615238, 3.084891, -0.203667, -6.890127, -5.996200, -4.324850, 4.625051, 8.263287, 5.757383, -2.636652, 9.009836, -6.672426, 3.797410, 1.110939, -4.861628, 0.015860, -1.888847, 5.899277, 9.101057, -7.533661, -7.053039, -4.462314, -3.804284, 4.272889, -4.814819, -7.549477, -0.159527, 7.401611, 1.193147, 6.313938, -5.368832, 5.667099, -6.233354, -4.923887, -6.551764, 4.256740, 9.467678, 2.658317, -2.260941, 8.950677, 8.248334, 0.824229, 3.046800, 8.314599, -1.859607, 8.570385, 2.675805, 7.779832, -3.581234, -3.411425, 5.548132, -9.055267, -4.895501, -3.418186}, 94, output, 11);
printf("#####END#####");
test_error(res == 0, "Funkcja create_histogram() powinna zwrócić 0, a zwróciłą %d", res);
int ok = 0;
for (int i = 0; i < 11; ++i)
ok += output[i] != expected_array[i];
if (ok)
{
printf("Powinno być: [4, 3, 6, 7, 4, 5, 1, 4, 8, 4, 0]\n");
printf("\nTablica po wywołaniu funkcji create_histogram: ");
for (int i = 0; i < 11; ++i)
printf("%d ", output[i]);
printf("\n");
test_error(ok == 0, "Funkcja create_histogram() niepoprawnie wypełniła tablicę");
}
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 6: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST6(void)
{
// informacje o teście
test_start(6, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
const int expected_array[] = {8, 4, 5, 5, 3, 6, 8, 6, 4, 2, 2, 6, 1, 6, 2, 6, 5, 7, 6, 1, 0};
int output[] = {1, -1, -2, 0, 2, -2, 0, 1, 0, 1, 1, 2, 1, 0, 2, 0, -1, 0, 1, 0, -1};
printf("#####START#####");
int res = create_histogram((float[]){16.477534, 5.318532, 11.209758, 18.781233, 0.910973, 5.468827, 15.744804, 5.701713, 17.371865, 10.886605, 18.413477, 13.515760, 4.599286, 4.332344, 7.414142, 12.588778, 18.459028, 11.250083, 5.869510, 18.645099, 2.128613, 13.496038, 19.521818, 6.603413, 0.668144, 1.587733, 0.835229, 18.278604, 11.888081, 18.128653, 15.329132, 2.523744, 0.750575, 9.962327, 8.561655, 14.993528, 3.332957, 2.510690, 10.826899, 6.520790, 6.262656, 1.574081, 17.617181, 11.092647, 6.860362, 4.307359, 13.958382, 8.962122, 16.303581, 17.483858, 7.577282, 8.288654, 3.093816, 3.639764, 7.958872, 0.018838, 13.612911, 16.046715, 0.424064, 7.594547, 9.175843, 17.944282, 14.379548, 2.779954, 15.903661, 15.405351, 5.558165, 3.852606, 15.196079, 17.889649, 6.179829, 17.318316, 8.785235, 0.677155, 6.842997, 13.960929, 11.908852, 6.306435, 7.980321, 2.196513, 0.159639, 1.619351, 11.353328, 6.377925, 13.785571, 17.931171, 7.864423, 15.834867, 16.630432, 5.139993, 16.567097, 1.876747, 3.607727}, 93, output, 21);
printf("#####END#####");
test_error(res == 0, "Funkcja create_histogram() powinna zwrócić 0, a zwróciłą %d", res);
int ok = 0;
for (int i = 0; i < 21; ++i)
ok += output[i] != expected_array[i];
if (ok)
{
printf("Powinno być: [8, 4, 5, 5, 3, 6, 8, 6, 4, 2, 2, 6, 1, 6, 2, 6, 5, 7, 6, 1, 0]\n");
printf("\nTablica po wywołaniu funkcji create_histogram: ");
for (int i = 0; i < 21; ++i)
printf("%d ", output[i]);
printf("\n");
test_error(ok == 0, "Funkcja create_histogram() niepoprawnie wypełniła tablicę");
}
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 7: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST7(void)
{
// informacje o teście
test_start(7, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
const int expected_array[] = {6, 7, 4, 13, 10, 11, 7, 11, 4, 9, 12, 11, 9, 8, 3, 6, 8, 7, 12, 9, 9, 10, 6, 11, 6, 5, 13, 14, 13, 15, 8, 10, 6, 9, 16, 12, 6, 5, 7, 8, 6, 7, 10, 6, 11, 12, 12, 17, 10, 13, 13, 10, 7, 8, 9, 6, 7, 7, 19, 12, 9, 6, 11, 7, 6, 6, 8, 10, 17, 5, 8, 14, 4, 6, 16, 10, 4, 6, 12, 9, 12, 8, 7, 5, 9, 7, 10, 11, 0};
int output[] = {-2, 0, -1, -1, 1, 2, -2, 2, -1, 2, -2, 1, 2, 2, 0, 0, -1, -2, -2, 0, 0, 2, -2, -2, 1, -2, 1, -1, 0, -2, 2, -1, -2, -2, -1, 1, 0, -2, 1, -2, -1, 0, 0, -2, -1, 0, 0, -2, -1, 2, 1, 1, 0, 2, -1, -2, 0, 2, 1, 0, 1, -1, -2, 0, -1, -2, -2, 2, -2, 2, -1, 0, 0, 1, 1, -1, 1, -2, 1, 0, 1, -1, -2, 1, 0, -2, -1, 2, -2};
printf("#####START#####");
int res = create_histogram((float[]){13.136158, 70.724738, 83.161277, 71.347509, 74.759079, 16.303557, 39.025923, 71.423331, 41.202459, 12.872501, 54.417110, 31.279616, 52.760103, 58.597958, 58.304714, 76.211839, 72.392067, 65.302988, 11.752797, 46.966899, 87.787339, 45.818923, 45.232256, 76.371069, 53.926308, 63.120514, 57.348695, 69.089210, 18.999313, 68.050034, 38.635149, 27.886792, 3.317001, 45.585477, 46.445116, 42.974148, 77.807967, 52.572426, 13.086586, 4.360870, 7.293444, 44.423242, 49.644166, 74.372066, 5.527066, 58.112360, 25.251683, 5.372896, 87.241819, 68.916804, 49.974876, 80.597179, 68.388160, 56.063809, 0.241732, 71.120818, 0.000098, 42.531629, 18.371790, 26.345384, 9.955519, 81.283099, 7.422514, 82.888842, 24.101188, 67.216780, 23.706881, 64.226622, 18.410253, 14.095312, 29.341028, 36.493375, 71.029182, 51.827978, 21.252035, 75.852450, 34.449141, 32.328896, 1.565549, 60.470556, 82.901496, 3.422390, 10.631225, 8.242202, 48.506137, 60.988561, 10.418581, 11.084254, 20.285021, 6.325751, 1.741322, 52.199626, 4.526537, 51.638517, 84.749395, 67.433153, 50.648453, 82.309663, 16.084922, 59.246770, 4.907274, 49.047898, 85.722142, 15.863240, 84.286266, 59.278988, 24.023996, 31.079296, 79.428540, 48.018466, 24.790779, 39.946644, 35.062570, 55.231468, 63.877828, 65.189967, 15.531635, 58.118867, 78.169185, 12.319479, 13.404758, 79.403327, 35.431530, 48.839085, 0.557764, 43.814905, 19.129582, 34.708999, 34.627771, 86.982158, 35.138226, 81.186912, 70.009405, 73.991549, 37.467925, 8.718773, 62.996580, 50.165703, 5.352609, 47.546115, 61.219540, 44.919765, 69.616959, 68.895661, 21.119409, 68.173463, 65.220593, 10.263617, 33.722236, 46.549094, 36.994824, 84.567053, 59.664347, 47.986060, 60.180192, 52.960804, 4.826290, 31.318974, 38.728070, 6.807674, 17.831660, 34.286837, 70.743461, 74.144766, 15.059535, 46.382976, 51.758328, 54.405327, 21.924962, 48.286742, 6.528193, 28.639201, 34.584973, 7.511164, 45.017847, 63.075412, 55.438851, 27.167909, 42.779100, 16.931112, 60.791327, 53.657664, 80.009452, 74.544373, 61.037305, 10.334914, 81.699096, 40.169600, 29.292534, 30.080050, 35.687197, 74.908704, 31.547225, 47.217828, 18.115212, 35.225624, 18.313302, 68.489340, 28.012909, 55.139231, 46.129643, 39.990536, 10.787691, 5.008235, 67.580151, 54.918210, 86.000028, 31.891584, 62.799755, 34.911661, 25.780186, 34.905888, 48.470378, 21.382946, 78.629882, 47.411844, 83.903297, 10.336414, 66.249160, 40.879863, 49.137671, 46.464566, 79.006855, 80.347412, 40.454445, 19.788912, 17.140552, 17.831124, 62.513903, 67.510512, 45.262270, 49.865474, 81.562405, 85.704802, 50.992612, 42.265344, 27.665285, 79.776307, 32.237231, 77.742525, 14.174908, 12.259664, 43.005021, 37.723692, 28.229086, 6.597711, 84.711186, 15.724705, 28.401531, 80.866755, 48.215900, 62.167880, 43.809848, 74.504752, 35.232911, 26.037952, 62.596780, 87.273362, 28.860514, 34.817632, 35.203427, 72.681571, 81.256975, 35.071134, 28.707131, 73.566945, 57.874910, 16.670988, 59.892695, 50.817533, 7.216746, 86.368432, 20.220911, 50.994587, 49.969861, 62.876986, 66.949795, 74.959951, 13.465102, 31.489793, 56.161240, 20.084984, 82.374628, 11.207047, 36.221824, 78.338332, 68.483337, 86.260366, 46.373786, 23.368069, 68.356494, 68.322982, 18.934140, 74.340313, 18.664613, 50.061490, 48.090020, 27.780934, 32.344905, 86.630850, 18.208926, 64.023903, 72.683050, 62.631605, 47.577668, 34.757821, 49.597309, 51.179835, 47.216233, 75.152924, 46.110886, 53.004300, 25.713976, 74.083988, 71.413716, 1.885536, 54.166218, 6.035683, 83.691002, 67.106185, 75.655954, 28.154196, 26.393051, 67.283913, 6.326763, 23.626781, 1.812875, 27.922326, 36.898084, 36.648016, 21.010545, 26.593972, 61.552535, 55.714388, 60.689685, 5.764352, 37.806972, 12.140443, 44.970065, 50.578620, 9.021938, 3.823394, 11.979622, 30.182852, 47.191865, 30.206374, 71.575044, 24.277489, 32.198972, 35.920810, 19.080147, 5.622107, 81.485727, 44.927952, 33.430789, 22.272076, 71.357084, 71.522846, 85.462102, 33.044506, 29.787156, 29.838213, 41.344118, 59.930559, 33.827594, 51.083230, 20.729402, 44.669623, 41.717714, 54.051344, 58.165741, 30.882837, 74.638045, 30.093047, 51.518706, 74.065347, 78.219213, 33.396211, 45.921435, 46.397253, 27.480468, 10.923278, 5.025727, 16.083337, 48.144370, 87.524387, 42.623543, 70.823338, 78.622963, 26.330031, 70.818045, 79.409575, 38.367637, 59.540997, 23.986436, 72.228708, 11.659674, 87.806775, 4.148731, 3.800596, 27.976730, 87.754512, 12.196824, 33.502948, 68.557229, 59.861422, 87.804147, 33.645940, 13.098385, 63.076016, 65.453786, 45.102610, 79.449478, 80.207666, 45.105338, 11.692682, 59.547100, 19.327099, 66.433266, 27.561978, 48.070061, 68.372314, 38.643936, 84.794360, 50.239593, 77.785308, 43.608219, 3.085588, 26.579420, 32.775462, 23.840414, 16.513448, 44.014358, 85.712458, 7.613957, 39.890428, 39.961588, 13.841682, 27.498835, 58.414679, 35.168392, 11.239301, 24.485033, 42.751259, 42.330706, 71.023825, 4.575069, 55.587157, 50.943019, 47.517868, 86.626502, 76.918008, 22.691031, 28.553727, 26.567265, 84.404641, 51.604292, 50.565394, 69.562768, 26.888636, 55.790003, 29.098058, 42.355337, 21.081785, 78.437986, 15.959381, 23.999439, 14.342079, 80.858590, 84.570048, 61.613686, 2.869254, 4.000543, 86.376475, 41.462163, 31.173868, 73.856643, 29.566917, 47.031212, 51.104042, 31.555564, 74.365820, 58.376944, 58.185444, 21.391707, 2.548977, 11.341577, 3.006112, 58.303886, 86.505327, 87.829732, 9.394507, 47.146265, 56.635048, 3.001027, 34.727121, 81.489465, 12.891350, 29.428820, 27.510675, 70.884681, 40.716194, 68.536631, 39.503740, 64.128079, 87.427330, 57.182169, 40.956865, 0.697592, 27.859320, 59.588095, 85.424208, 0.336821, 51.320207, 79.765967, 9.708638, 49.413482, 52.168669, 78.761677, 16.691821, 16.235801, 12.971517, 75.968737, 58.187713, 47.442592, 58.904331, 34.740467, 47.200307, 47.126059, 63.893054, 28.071318, 66.418333, 80.570869, 85.843622, 39.372976, 44.059169, 43.700428, 83.352713, 78.556987, 54.525285, 34.377435, 11.707095, 41.577210, 86.066558, 10.358392, 26.251360, 42.493104, 49.191299, 10.782446, 64.303210, 10.928282, 62.217202, 59.965683, 84.507039, 80.524035, 6.661200, 10.774381, 30.407961, 29.285326, 11.661787, 1.437271, 75.635900, 46.280463, 62.655431, 69.153216, 29.044459, 5.680265, 7.230501, 44.634129, 73.337637, 12.645075, 57.343308, 22.608919, 80.284439, 1.529252, 25.862253, 74.581974, 53.147747, 40.454667, 37.264364, 28.960655, 9.999782, 23.092089, 77.886329, 68.120395, 12.019419, 29.167824, 46.621083, 56.829335, 22.343950, 54.520517, 84.380575, 53.329518, 58.229565, 21.497201, 17.058952, 45.652469, 58.506908, 56.985217, 29.315018, 53.810067, 34.950915, 75.935442, 13.296032, 65.310559, 19.198292, 28.887707, 25.618479, 7.789471, 29.404998, 57.621533, 39.737047, 82.112543, 67.571714, 54.980607, 80.480108, 26.190169, 5.734770, 4.984546, 59.292759, 66.868736, 58.837293, 41.901488, 71.881811, 67.547872, 66.251515, 68.938776, 73.481572, 15.080863, 18.532173, 60.794758, 57.866582, 78.740064, 33.681000, 19.710808, 49.383476, 62.364678, 63.321002, 46.086271, 56.638145, 7.382924, 2.235257, 85.668307, 48.514913, 80.946393, 18.961233, 60.018480, 66.430131, 28.301634, 61.996586, 3.896033, 3.672818, 53.873299, 76.749568, 75.006431, 26.154145, 68.324396, 26.650671, 71.800331, 22.857211, 57.039001, 17.441185, 58.766329, 54.611493, 22.494592, 63.122109, 64.772930, 20.580811, 87.559095, 81.741553, 50.016619, 11.216197, 8.832429, 34.630536, 32.735277, 34.367186, 86.716998, 27.962224, 7.543586, 49.984232, 9.492635, 77.604612, 52.893448, 42.764963, 78.426726, 20.222250, 38.910350, 64.055584, 61.798041, 83.930061, 38.795711, 30.741307, 44.737966, 51.249526, 20.717470, 29.053485, 17.791802, 44.961495, 5.145181, 50.460671, 69.231995, 59.640032, 49.160537, 21.473149, 3.520645, 10.784309, 79.449695, 45.102764, 24.760753, 75.228521, 21.123951, 56.400778, 4.030568, 7.670622, 47.812579, 60.070297, 19.870686, 70.277025, 18.836494, 74.647925, 29.814098, 19.354499, 71.170549, 74.518598, 68.407520, 47.423358, 36.664174, 68.737961, 58.550590, 60.498073, 23.640815, 38.937698, 77.826442, 44.039361, 58.062947, 2.763872, 23.235834, 71.744160, 29.707100, 53.910768, 43.447932, 62.323202, 23.500725, 1.537564, 3.875224, 27.452846, 58.565828, 78.680219, 26.896416, 75.766203, 74.412818, 67.261021, 70.009601, 73.870699, 28.509079, 82.320245, 31.992112, 17.726840, 71.300073, 30.630935, 18.150639, 9.696686, 4.586582, 67.728092, 3.443676, 35.583287, 9.049375, 78.715592, 20.174136, 75.714241, 31.984227, 13.294293, 37.537369, 0.944460, 58.973305, 7.412232, 87.683077, 35.911098, 5.459924, 65.955080, 82.694584, 47.891710, 79.824322, 45.574622, 8.553072, 52.437796, 23.867397, 50.525162, 33.642956, 47.897365, 80.820773, 20.994592, 3.068465, 41.877096, 27.649403, 49.981732, 9.852089, 34.979197, 45.805847, 19.269268, 66.551088}, 801, output, 89);
printf("#####END#####");
test_error(res == 0, "Funkcja create_histogram() powinna zwrócić 0, a zwróciłą %d", res);
int ok = 0;
for (int i = 0; i < 89; ++i)
ok += output[i] != expected_array[i];
if (ok)
{
printf("Powinno być: [6, 7, 4, 13, 10, 11, 7, 11, 4, 9, 12, 11, 9, 8, 3, 6, 8, 7, 12, 9, 9, 10, 6, 11, 6, 5, 13, 14, 13, 15, 8, 10, 6, 9, 16, 12, 6, 5, 7, 8, 6, 7, 10, 6, 11, 12, 12, 17, 10, 13, 13, 10, 7, 8, 9, 6, 7, 7, 19, 12, 9, 6, 11, 7, 6, 6, 8, 10, 17, 5, 8, 14, 4, 6, 16, 10, 4, 6, 12, 9, 12, 8, 7, 5, 9, 7, 10, 11, 0]\n");
printf("\nTablica po wywołaniu funkcji create_histogram: ");
for (int i = 0; i < 89; ++i)
printf("%d ", output[i]);
printf("\n");
test_error(ok == 0, "Funkcja create_histogram() niepoprawnie wypełniła tablicę");
}
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 8: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST8(void)
{
// informacje o teście
test_start(8, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
const int expected_array[] = {5, 11, 9, 8, 12, 12, 11};
int output[] = {-1, 0, -1, 2, -1, -2, -1};
printf("#####START#####");
int res = create_histogram((float[]){5.306186, 3.469854, 5.584938, 1.700203, 7.439263, 0.782366, 3.789746, 4.595674, 10.115835, 3.533284, 10.604733, 6.477287, 1.357688, 3.642931, 3.542456, 4.895706, 6.348691, 1.012855, 4.848307, 9.396675, 8.237131, 4.602098, 3.852014, 7.466906, 1.724754, 10.396045, 3.981893, 6.928553, 8.956617, 1.734809, 9.481058, 4.228850, 6.198118, 9.571572, 0.946367, 10.133983, 9.621540, 9.254568, 1.121544, 4.873993, 6.155764, 6.910100, 1.123636, 1.315558, 5.389276, 9.926547, 10.131239, 6.243230, 6.924830, 5.070787, 6.591831, 6.561414, 2.964386, 10.930803, 8.525999, 5.023025, 4.521506, 0.468242, 2.389985, 4.807493, 8.793501, 1.732636, 1.352504, 7.153009, 10.503434, 8.703331, 8.956058, 5.825978, 9.496916, 8.595933, 5.101543, 1.547795, 5.689870, 0.191027, 4.327090, 8.661962, 5.773067, 4.595416, 7.531218, 0.831476, 2.377101, 5.699772, 2.894374, 7.727058, 5.154591, 9.113751, 6.049198, 7.243001, 4.136706, 2.466175, 2.106537, 2.672478, 4.761295, 9.828940, 2.155959, 3.739409, 5.972079, 2.430778, 8.429895}, 99, output, 7);
printf("#####END#####");
test_error(res == 0, "Funkcja create_histogram() powinna zwrócić 0, a zwróciłą %d", res);
int ok = 0;
for (int i = 0; i < 7; ++i)
ok += output[i] != expected_array[i];
if (ok)
{
printf("Powinno być: [5, 11, 9, 8, 12, 12, 11]\n");
printf("\nTablica po wywołaniu funkcji create_histogram: ");
for (int i = 0; i < 7; ++i)
printf("%d ", output[i]);
printf("\n");
test_error(ok == 0, "Funkcja create_histogram() niepoprawnie wypełniła tablicę");
}
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 9: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST9(void)
{
// informacje o teście
test_start(9, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
const int expected_array[] = {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int output[] = {1, -2, -1, -1, -2, 0, 1, 0, 1, 2, -2};
printf("#####START#####");
int res = create_histogram((float[]){1.820243}, 1, output, 11);
printf("#####END#####");
test_error(res == 0, "Funkcja create_histogram() powinna zwrócić 0, a zwróciłą %d", res);
int ok = 0;
for (int i = 0; i < 11; ++i)
ok += output[i] != expected_array[i];
if (ok)
{
printf("Powinno być: [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n");
printf("\nTablica po wywołaniu funkcji create_histogram: ");
for (int i = 0; i < 11; ++i)
printf("%d ", output[i]);
printf("\n");
test_error(ok == 0, "Funkcja create_histogram() niepoprawnie wypełniła tablicę");
}
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 10: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST10(void)
{
// informacje o teście
test_start(10, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
const int expected_array[] = {7};
int output[] = {-2};
printf("#####START#####");
int res = create_histogram((float[]){6.133738, 2.514071, 2.834874, 8.638133, 8.227670, 3.638535, 5.661461, 5.523042, 3.320160, 1.981832, 1.577738, 10.068427, 2.022801, 5.894574, 3.756914, 4.355879, 10.140861, 2.130179, 6.005347, 10.996602, 0.931856, 1.726232, 8.224090, 7.483747, 1.609877, 10.918317, 4.726248, 3.789912, 10.624962, 0.483670, 0.047790, 1.575290, 8.624264, 7.184954, 0.238160, 6.385776, 2.202027, 1.450637, 9.274667, 1.786747, 4.200234, 3.154462, 4.832384, 2.730561, 3.066013, 6.050273, 9.861188, 10.569646, 4.975791, 1.946215, 0.026164, 0.537682, 0.217931, 7.782957, 6.986002, 9.999352, 6.150379, 1.822736, 8.230213, 1.864523, 6.353536, 1.090051}, 62, output, 1);
printf("#####END#####");
test_error(res == 0, "Funkcja create_histogram() powinna zwrócić 0, a zwróciłą %d", res);
int ok = 0;
for (int i = 0; i < 1; ++i)
ok += output[i] != expected_array[i];
if (ok)
{
printf("Powinno być: [7]\n");
printf("\nTablica po wywołaniu funkcji create_histogram: ");
for (int i = 0; i < 1; ++i)
printf("%d ", output[i]);
printf("\n");
test_error(ok == 0, "Funkcja create_histogram() niepoprawnie wypełniła tablicę");
}
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 11: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST11(void)
{
// informacje o teście
test_start(11, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
printf("#####START#####");
int res = create_histogram((float[]){5.711182, 8.353616, 5.839582, 5.170182}, 12, NULL, 17);
printf("#####END#####");
test_error(res == 1, "Funkcja create_histogram() powinna zwrócić 1, a zwróciłą %d", res);
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 12: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST12(void)
{
// informacje o teście
test_start(12, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
int output[] = {2, 2, 1, -1, -2, 2, -1, 0, -2, 0, 1};
printf("#####START#####");
int res = create_histogram(NULL, 12, output, 12);
printf("#####END#####");
test_error(res == 1, "Funkcja create_histogram() powinna zwrócić 1, a zwróciłą %d", res);
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 13: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST13(void)
{
// informacje o teście
test_start(13, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
int output[] = {2, 2, 1, -1, -2, 2, -1, 0, -2, 0, 1};
printf("#####START#####");
int res = create_histogram((float[]){5.711182, 8.353616, 5.839582, 5.170182}, 0, output, 16);
printf("#####END#####");
test_error(res == 1, "Funkcja create_histogram() powinna zwrócić 1, a zwróciłą %d", res);
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 14: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST14(void)
{
// informacje o teście
test_start(14, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
int output[] = {2, 2, 1, -1, -2, 2, -1, 0, -2, 0, 1};
printf("#####START#####");
int res = create_histogram((float[]){5.711182, 8.353616, 5.839582, 5.170182}, 15, output, 0);
printf("#####END#####");
test_error(res == 1, "Funkcja create_histogram() powinna zwrócić 1, a zwróciłą %d", res);
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 15: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST15(void)
{
// informacje o teście
test_start(15, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
int output[] = {2, 2, 1, -1, -2, 2, -1, 0, -2, 0, 1};
printf("#####START#####");
int res = create_histogram((float[]){5.711182, 8.353616, 5.839582, 5.170182}, -11, output, 11);
printf("#####END#####");
test_error(res == 1, "Funkcja create_histogram() powinna zwrócić 1, a zwróciłą %d", res);
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 16: Sprawdzanie poprawności działania funkcji create_histogram
//
void UTEST16(void)
{
// informacje o teście
test_start(16, "Sprawdzanie poprawności działania funkcji create_histogram", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
int output[] = {2, 2, 1, -1, -2, 2, -1, 0, -2, 0, 1};
printf("#####START#####");
int res = create_histogram((float[]){5.711182, 8.353616, 5.839582, 5.170182}, 13, output, -11);
printf("#####END#####");
test_error(res == 1, "Funkcja create_histogram() powinna zwrócić 1, a zwróciłą %d", res);
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 17: Sprawdzanie poprawności działania funkcji display
//
void UTEST17(void)
{
// informacje o teście
test_start(17, "Sprawdzanie poprawności działania funkcji display", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
int tab[] = {0, 4, 0, 1};
//-------------1-----------------------
printf("\n***TEST 1***\n\n");
printf("***START***\n");
display_vector(tab, 0);
printf("***END***\n");
//-------------2-----------------------
printf("\n***TEST 2***\n\n");
printf("***START***\n");
display_vector(tab, -4);
printf("***END***\n");
//-------------3-----------------------
printf("\n***TEST 3***\n\n");
printf("***START***\n");
display_vector(tab, 4);
printf("***END***\n");
//-------------4-----------------------
printf("\n***TEST 4***\n\n");
printf("***START***\n");
display_vector(tab, 4 - 1);
printf("***END***\n");
onerror_terminate(); // przerwanie wszystkich testów jednostkowych (np. coś jest mocno nie tak z kodem)
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 18: Sprawdzanie poprawności działania funkcji read_vector_float
//
void UTEST18(void)
{
// informacje o teście
test_start(18, "Sprawdzanie poprawności działania funkcji read_vector_float", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
const int expected_result = 10;
const float expected_array[] = {6.000000, 6.000000, 10.000000, 7.000000, 6.000000, -3.000000, -8.000000, 9.000000, 8.000000, -6.000000, 0.000000};
float dest[11];
int result = read_vector_float(dest, 11, 0);
test_error(result == expected_result, "Funkcja read_vector_float() powinna zwrócić %d, a zwróciła %d", expected_result, result);
int ok = 0;
for (int i = 0; i < expected_result; ++i)
ok += !(expected_array[i] + 0.001 >= dest[i] && expected_array[i] - 0.001 <= dest[i]);
test_error(ok == 0, "Funkcja read_vector_float() niepoprawnie pobrałá dane od użytkownika");
if (ok)
{
printf("Powinno być: [6.000000, 6.000000, 10.000000, 7.000000, 6.000000, -3.000000, -8.000000, 9.000000, 8.000000, -6.000000, 0.000000]\n");
printf("Jest: [");
for (int i = 0; i < expected_result - 1; ++i)
printf("%f, ", dest[i]);
printf("%f] ", dest[expected_result - 1]);
}
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 19: Sprawdzanie poprawności działania funkcji read_vector_float
//
void UTEST19(void)
{
// informacje o teście
test_start(19, "Sprawdzanie poprawności działania funkcji read_vector_float", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
const int expected_result = 7;
const float expected_array[] = {1.000000, -10.000000, 0.000000, -8.000000, -1.000000, -8.000000, -9.000000, -3.000000};
float dest[8];
int result = read_vector_float(dest, 8, -3);
test_error(result == expected_result, "Funkcja read_vector_float() powinna zwrócić %d, a zwróciła %d", expected_result, result);
int ok = 0;
for (int i = 0; i < expected_result; ++i)
ok += !(expected_array[i] + 0.001 >= dest[i] && expected_array[i] - 0.001 <= dest[i]);
test_error(ok == 0, "Funkcja read_vector_float() niepoprawnie pobrałá dane od użytkownika");
if (ok)
{
printf("Powinno być: [1.000000, -10.000000, 0.000000, -8.000000, -1.000000, -8.000000, -9.000000, -3.000000]\n");
printf("Jest: [");
for (int i = 0; i < expected_result - 1; ++i)
printf("%f, ", dest[i]);
printf("%f] ", dest[expected_result - 1]);
}
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 20: Sprawdzanie poprawności działania funkcji read_vector_float
//
void UTEST20(void)
{
// informacje o teście
test_start(20, "Sprawdzanie poprawności działania funkcji read_vector_float", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
const int expected_result = 0;
const float expected_array[] = {0.000000};
float dest[5];
int result = read_vector_float(dest, 5, 0);
test_error(result == expected_result, "Funkcja read_vector_float() powinna zwrócić %d, a zwróciła %d", expected_result, result);
int ok = 0;
for (int i = 0; i < expected_result; ++i)
ok += !(expected_array[i] + 0.001 >= dest[i] && expected_array[i] - 0.001 <= dest[i]);
test_error(ok == 0, "Funkcja read_vector_float() niepoprawnie pobrałá dane od użytkownika");
if (ok)
{
printf("Powinno być: [0.000000]\n");
printf("Jest: [");
for (int i = 0; i < expected_result - 1; ++i)
printf("%f, ", dest[i]);
printf("%f] ", dest[expected_result - 1]);
}
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 21: Sprawdzanie poprawności działania funkcji read_vector_float
//
void UTEST21(void)
{
// informacje o teście
test_start(21, "Sprawdzanie poprawności działania funkcji read_vector_float", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
const int expected_result = 8;
const float expected_array[] = {-9.000000, -3.000000, 7.000000, 4.000000, 2.000000, 10.000000, -7.000000, 3.000000};
float dest[8];
int result = read_vector_float(dest, 8, -6);
test_error(result == expected_result, "Funkcja read_vector_float() powinna zwrócić %d, a zwróciła %d", expected_result, result);
int ok = 0;
for (int i = 0; i < expected_result; ++i)
ok += !(expected_array[i] + 0.001 >= dest[i] && expected_array[i] - 0.001 <= dest[i]);
test_error(ok == 0, "Funkcja read_vector_float() niepoprawnie pobrałá dane od użytkownika");
if (ok)
{
printf("Powinno być: [-9.000000, -3.000000, 7.000000, 4.000000, 2.000000, 10.000000, -7.000000, 3.000000]\n");
printf("Jest: [");
for (int i = 0; i < expected_result - 1; ++i)
printf("%f, ", dest[i]);
printf("%f] ", dest[expected_result - 1]);
}
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 22: Sprawdzanie poprawności działania funkcji read_vector_float
//
void UTEST22(void)
{
// informacje o teście
test_start(22, "Sprawdzanie poprawności działania funkcji read_vector_float", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
int expected_result = -1;
float dest[5];
printf("#####START#####");
int result = read_vector_float(dest, 0, 6);
printf("#####END#####");
test_error(result == expected_result, "Funkcja read_vector_float() powinna zwrócić %d, a zwróciła %d", expected_result, result);
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 23: Sprawdzanie poprawności działania funkcji read_vector_float
//
void UTEST23(void)
{
// informacje o teście
test_start(23, "Sprawdzanie poprawności działania funkcji read_vector_float", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
int expected_result = -1;
float dest[8];
printf("#####START#####");
int result = read_vector_float(dest, -3, 5);
printf("#####END#####");
test_error(result == expected_result, "Funkcja read_vector_float() powinna zwrócić %d, a zwróciła %d", expected_result, result);
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
//
// Test 24: Sprawdzanie poprawności działania funkcji read_vector_float
//
void UTEST24(void)
{
// informacje o teście
test_start(24, "Sprawdzanie poprawności działania funkcji read_vector_float", __LINE__);
// uwarunkowanie zasobów - pamięci, itd...
test_file_write_limit_setup(33554432);
rldebug_reset_limits();
//
// -----------
//
int expected_result = -1;
printf("#####START#####");
int result = read_vector_float(NULL, -1, -9);
printf("#####END#####");
test_error(result == expected_result, "Funkcja read_vector_float() powinna zwrócić %d, a zwróciła %d", expected_result, result);
//
// -----------
//
// przywrócenie podstawowych parametów przydzielania zasobów (jeśli to tylko możliwe)
rldebug_reset_limits();
test_file_write_limit_restore();
test_ok();
}
enum run_mode_t { rm_normal_with_rld = 0, rm_unit_test = 1, rm_main_test = 2 };
int __wrap_main(volatile int _argc, char** _argv, char** _envp)
{
int volatile vargc = _argc;
char ** volatile vargv = _argv, ** volatile venvp = _envp;
volatile enum run_mode_t run_mode = rm_unit_test; // -1
volatile int selected_test = -1;
if (vargc > 1)
{
char* smode = strtok(vargv[1], ",");
char* stest = strtok(NULL, "");
char *errptr = NULL;
run_mode = (enum run_mode_t)strtol(smode, &errptr, 10);
if (*errptr == '\x0')
{
memmove(vargv + 1, vargv + 2, sizeof(char*) * (vargc - 1));
vargc--;
if (stest != NULL)
{
int val = (int)strtol(stest, &errptr, 10);
if (*errptr == '\x0')
selected_test = val;
}
}
}
// printf("runmode=%d; selected_test=%d\n", run_mode, selected_test);
// inicjuj testy jednostkowe
unit_test_init(run_mode, "unit_test_v2.c");
test_limit_init();
rldebug_set_reported_severity_level(MSL_FAILURE);
if (run_mode == rm_normal_with_rld)
{
// konfiguracja ograniczników
rldebug_reset_limits();
// uruchom funkcję main Studenta a potem wyświetl podsumowanie sterty i zasobów
volatile int ret_code = rdebug_call_main(tested_main, vargc, vargv, venvp);
rldebug_reset_limits();
int leaks_detected = rldebug_show_leaked_resources(0);
if (leaks_detected)
raise(SIGHEAP);
return ret_code;
}
if (run_mode == rm_unit_test)
{
test_title("Testy jednostkowe");
void (*pfcn[])(void) =
{
UTEST1, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST2, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST3, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST4, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST5, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST6, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST7, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST8, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST9, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST10, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST11, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST12, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST13, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST14, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST15, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST16, // Sprawdzanie poprawności działania funkcji create_histogram
UTEST17, // Sprawdzanie poprawności działania funkcji display
UTEST18, // Sprawdzanie poprawności działania funkcji read_vector_float
UTEST19, // Sprawdzanie poprawności działania funkcji read_vector_float
UTEST20, // Sprawdzanie poprawności działania funkcji read_vector_float
UTEST21, // Sprawdzanie poprawności działania funkcji read_vector_float
UTEST22, // Sprawdzanie poprawności działania funkcji read_vector_float
UTEST23, // Sprawdzanie poprawności działania funkcji read_vector_float
UTEST24, // Sprawdzanie poprawności działania funkcji read_vector_float
NULL
};
for (int idx = 0; pfcn[idx] != NULL && !test_get_session_termination_flag(); idx++)
{
if (selected_test == -1 || selected_test == idx + 1)
pfcn[idx]();
// limit niezaliczonych testów, po jakim testy jednostkowe zostaną przerwane
if (test_session_get_fail_count() >= 1000)
test_terminate_session();
}
test_title("RLDebug :: Analiza wycieku zasobów");
// sprawdź wycieki pamięci
int leaks_detected = rldebug_show_leaked_resources(1);
test_set_session_leaks(leaks_detected);
// poinformuj serwer Mrówka o wyniku testu - podsumowanie
test_title("Podsumowanie");
if (selected_test == -1)
test_summary(24); // wszystkie testy muszą zakończyć się sukcesem
else
test_summary(1); // tylko jeden (selected_test) test musi zakończyć się sukcesem
return EXIT_SUCCESS;
}
if (run_mode == rm_main_test)
{
test_title("Testy funkcji main()");
void (*pfcn[])(int, char**, char**) =
{
NULL
};
for (volatile int idx = 0; pfcn[idx] != NULL && !test_get_session_termination_flag(); idx++)
{
if (selected_test == -1 || selected_test == idx + 1)
pfcn[idx](vargc, vargv, venvp);
// limit niezaliczonych testów, po jakim testy jednostkowe zostaną przerwane
if (test_session_get_fail_count() >= 1000)
test_terminate_session();
}
test_title("RLDebug :: Analiza wycieku zasobów");
// sprawdź wycieki pamięci
int leaks_detected = rldebug_show_leaked_resources(1);
test_set_session_leaks(leaks_detected);
// poinformuj serwer Mrówka o wyniku testu - podsumowanie
test_title("Podsumowanie");
if (selected_test == -1)
test_summary(0); // wszystkie testy muszą zakończyć się sukcesem
else
test_summary(1); // tylko jeden (selected_test) test musi zakończyć się sukcesem
return EXIT_SUCCESS;
}
printf("*** Nieznana wartość RunMode: %d", (int)run_mode);
abort();
}